package cloudspace.controlpanel.filemanager;

import java.util.Comparator;

import cloudspace.vm.filesystem.CSPath;


// ----------------------------------------------------------
/**
 * Sorts files in the list view so that directories come before files, and
 * directories/files are in ascending alphabetical order in each group.
 */
public class DirectoriesFirstCSPathComparator implements Comparator<CSPath>
{
    // ----------------------------------------------------------
    public int compare( CSPath path1, CSPath path2 )
    {
        if ( path1.isDirectory() && path2.isFile() )
        {
            return -1;
        }
        else if ( path1.isFile() && path2.isDirectory() )
        {
            return 1;
        }
        else
        {
            return path1.getName().compareToIgnoreCase( path2.getName() );
        }
    }
}
